#!/bin/bash

# source /etc/profile
appName=cava_smu
target=smu

function del()
{
    #rm -rf main 
    rm -rf ${target}
    rm -rf ${target}.tar.gz
}

GIT_BRANCH=`git rev-parse --abbrev-ref HEAD || echo`
GIT_SHA=`git rev-parse --short HEAD || echo`
BUILD_AT=`date "+%Y-%m-%dT%H:%M:%S"`

os_type=$1
if [ "$os_type" == "" ];then
    os_type=amd64
fi
echo "os type: $os_type"

del
CGO_ENABLED=0 GOOS=linux GOARCH=$os_type go build -ldflags "-X main.GitBranch=${GIT_BRANCH} -X main.GitSHA=${GIT_SHA} -X main.BuildAt=${BUILD_AT}" -o ${appName} -mod=vendor
#cp -rf main ${appName}
del

mkdir ${target}
cp -rf ${appName} ${target}
cp -rf config.xml ${target}
cp -rf start.sh ${target}
cp -rf stop.sh ${target}
cp -rf ../assets/templates ${target}
git log -1 .. > ${target}/version.info

tar -czvf ${target}.tar.gz ${target}
rm -rf ${target}
rm -rf ${appName}

echo "pack ${appName} to ${target}.tar.gz succeed."
